package com.xxl.job.admin.core;

import com.xxl.job.admin.core.scheduler.XxlJobScheduler;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;


/**
 * @Author fanchunshuai
 * @Description 启动初始化监听器
 * @Date 2023/2/22
 * @Version 1.0
 * fix https://gitee.com/xuxueli0323/xxl-job/issues/I62N1M
 */
@Component
public class InitScheduleListener implements ApplicationListener<ApplicationStartedEvent> {

    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        try {
            //通过单例 + spring 启动监听来初始化
            XxlJobScheduler.getInstance().init();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
